<template>
  <div id="app">
    <!-- 移除transition，避免组件切换时的空白期 -->
    <MenuView v-if="gameStatus === 'menu'" />
    <RoomLobby v-else-if="gameStatus === 'lobby'" />
    <GameView v-else-if="gameStatus === 'playing' || gameStatus === 'loading'" />
    <ResultView v-else-if="gameStatus === 'finished'" />
  </div>
</template>

<script setup>
import { computed } from 'vue';
import { useGameStore } from './store/game';
import { useMultiplayerStore } from './store/multiplayer';
import MenuView from './views/MenuView.vue';
import RoomLobby from './views/RoomLobby.vue';
import GameView from './views/GameView.vue';
import ResultView from './views/ResultView.vue';

const gameStore = useGameStore();
const multiplayerStore = useMultiplayerStore();

const gameStatus = computed(() => {
  // 如果在多人房间中
  if (multiplayerStore.isInRoom && multiplayerStore.gameMode === 'multiplayer') {
    // 检查游戏store的状态，如果是loading、playing或finished，则显示对应界面
    if (gameStore.gameStatus === 'loading' ||
        gameStore.gameStatus === 'playing' ||
        gameStore.gameStatus === 'finished') {
      return gameStore.gameStatus;
    }
    // 否则显示房间等待界面
    return 'lobby';
  }
  // 单人游戏直接返回gameStore状态
  return gameStore.gameStatus;
});
</script>

<style>
#app {
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
  overflow: hidden;
  position: relative;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 全局样式 */
* {
  box-sizing: border-box;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  border: none;
  outline: none;
  font-family: inherit;
  transition: all 0.2s ease;
}

button:active {
  transform: scale(0.95);
}

/* 卡片基础样式 */
.card {
  width: 60px;
  height: 90px;
  background: white;
  border: 2px solid #333;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  color: #333; /* 默认黑色字体 */
}

.card:hover {
  transform: translateY(-5px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.card.selected {
  transform: translateY(-10px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.4);
  border-color: #ff6b6b;
}

.card-rank {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 2px;
}

.card-symbol {
  font-size: 24px;
  margin-bottom: 4px;
}

.card-name {
  font-size: 12px;
}

/* 按钮样式 */
.btn {
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 16px;
  font-weight: bold;
  color: white;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.btn-secondary {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.btn-success {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:disabled:active {
  transform: none;
}

/* 消息提示 */
.message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: bold;
  color: white;
  z-index: 1000;
  animation: slideDown 0.3s ease;
}

.message.info {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.message.success {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.message.error {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

@keyframes slideDown {
  from {
    transform: translateX(-50%) translateY(-100%);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

/* 响应式 */
@media (max-width: 768px) {
  .card {
    width: 50px;
    height: 75px;
  }
  
  .card-rank {
    font-size: 14px;
  }
  
  .card-symbol {
    font-size: 20px;
  }
  
  .card-name {
    font-size: 10px;
  }
  
  .btn {
    padding: 10px 20px;
    font-size: 14px;
  }
}
</style>